package 优先算法.递归_搜索与回溯.综合案列.字母大小写排列;

import java.util.ArrayList;
import java.util.List;

public class Main2 {
    public static void main(String[] args) {
        Solution so = new Solution();
        List<String> ret = so.letterCasePermutation("a1b2");
        System.out.println(ret);
    }
}

class Solution2 {
    List<String> ret;
    StringBuffer path;
    public List<String> letterCasePermutation(String s) {
        ret = new ArrayList<>();
        path = new StringBuffer();
        dfs(s, 0);
        return ret;
    }

    public void dfs(String s, int pos) {
        if (pos == s.length()) {
            ret.add(path.toString());
            return;
        }
        //不变
        char ch =s.charAt(pos);
        path.append(ch);
        dfs(s,pos+1);
        path.setLength(path.length()-1);

        //变
        if(ch < '0' || ch > '9'){
            path.append(change(ch));
            dfs(s,pos+1);
            path.setLength(path.length()-1);
        }
    }

    private static char change(char ch) {
        if(ch >='a' && ch <= 'z'){
            return ch -=32;
        }else{
            return ch +=32;
        }
    }
}